using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using Utils.Explorer;
using ImdbServices;
using MyCollections.Model;

namespace MyCollections.Forms
{
    public partial class fFindImdbMovie : Form
    {
        public MovieCollection Movie;

        public fFindImdbMovie()
        {
            InitializeComponent();
            // set mode to SINGLE
            this.listViewMovie.setMode(this.listViewMovie.SINGLE);
        }

        public fFindImdbMovie(string title, string action): this()
        {
            this.tb_title.Text = title;
            updateButtons(action);
        }

        public fFindImdbMovie(fMain parent):this()
        {
            this.MdiParent = parent;
            this.listViewMovie.MdiParent = parent;
            this.bt_save.Enabled = false;
            updateButtons("save");
        }

        #region UTILS
        // ++++++++++++++++++++++++++++++++++++++++++++++++++++
        private void updateButtons(string visualization_type)
        {
            switch (visualization_type)
            {
                case "showdialog": 
                    // TYPE: showdialog use bt_ok and bt_cancel
                    this.bt_cancel.Visible = true;
                    this.bt_ok.Visible = true;
                    this.bt_save.Visible = false;
                    break;
                case "save":
                    // TYPE: showdialog use bt_save and bt_cancel
                    this.bt_cancel.Visible = true;
                    this.bt_ok.Visible = false;
                    this.bt_save.Visible = true;
                    break;
                default: break;
            }
        }
        #endregion

        #region EVENTS
        // ++++++++++++++++++++++++++++++++++++++++++++++++++++
        private void bt_search_Click(object sender, EventArgs e)
        {
            string movie_title = this.tb_title.Text;
            if (String.IsNullOrEmpty(movie_title))
                return;

            bool results = false;
            MovieCollection[] moviesResult = null;

            //clear before data
            this.listViewMovie.RemoveAllItens();

            // find data movie in Imdb
            ImdbService service = new ImdbService(true,true,true,this.listViewMovie);
            service.FindMovie(movie_title);
            if (moviesResult != null && moviesResult.Length > 0)
                results = true;
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            this.Movie = new MovieCollection();
            this.Dispose();
        }

        private void bt_ok_Click(object sender, EventArgs e)
        {
            if (this.listViewMovie.Lb_results.SelectedIndex > 0)
            {
                this.Movie = (MovieCollection)this.listViewMovie.Lb_results.SelectedItem;
                this.Dispose();
            }
        }
        // ----------------------------------------------------
        #endregion        
    }
}